<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript">
	
	var _dataGrid;
	$(function() {
		
		_dataGrid = $('#_dataGrid').datagrid({
			singleSelect : true,
			url : '/expressFeeController/dataGrid',
			fit : true,
			fitColumns : false,
			border : false,
			pagination : true,
			idField : 'id',
			pageSize : 10,
			pageList : [ 10, 20, 30, 40, 50 ],
			sortName : 'provinceId',
			sortOrder : 'asc',
			checkOnSelect : false,
			selectOnCheck : false,
			nowrap : true,
			queryParams : {"expressId":"${expressId}"},
			columns : [ [  {
				field : 'provinceName',
				title :'区域',
				width : 100
			},{
				field : 'firstWeight',
				title :'首重（千克）',
				width : 100,
				formatter:function(val,rec){ 
					return val/1000;
				}
			},{
				field : 'firstWeightFee',
				title :'首重费用（元）',
				width : 100,
				formatter:function(val,rec){ 
					return val/100;
				}
			},{
				field : 'addedWeightFee',
				title :'续重费用（元/千克）',
				width : 100,
				formatter:function(val,rec){ 
					return val/100;
				}
			},{
				field : 'aging',
				title :'时效（天）',
				width : 100
			},{
				field : 'status',
				title :'状态',
				width : 100,
				formatter:function(val,rec){ 
					if(val == 1) {
						return '<span style="color:green">可用</span>';
					}else if(val == 2) {
						return '<span style="color:red">不可用</span>';
					}else {
						return '未知';
					}
				}
			},{
				field : 'gmtCreate',
				title : '创建时间',
				width : 150,
				formatter:function(val,rec){ 
					 var unixTimestamp = new Date(val);  
                     return unixTimestamp.format("yyyy-MM-dd hh:mm:ss");  
				}
			}, {
				field : 'gmtModify',
				title : '修改时间',
				width : 150,
				formatter:function(val,rec){ 
					if(val == "" || val == null) {
						return "";
					}
					 var unixTimestamp = new Date(val);  
                    return unixTimestamp.format("yyyy-MM-dd hh:mm:ss");  
				}
			} ] ],
			toolbar : '#toolbar',
			onLoadSuccess : function() {
				parent.$.messager.progress('close');
				$(this).datagrid('tooltip');
			}
		});
		
	});


	function deleteFun() {
		var row = _dataGrid.datagrid('getSelected');
		if(row == null) {
			return;
		}
		var id = row.id;
		parent.$.messager.confirm('询问', '您是否要删除当前快递费用？', function(b) {
			if (b) {
				parent.$.messager.progress({
					title : '提示',
					text : '数据处理中，请稍后....'
				});
				$.post('/expressFeeController/delete', {
					id : id
				}, function(result) {
					parent.$.messager.alert('提示', result.msg, 'info');
					if (result.success) {
						_dataGrid.datagrid('reload');
					}
					parent.$.messager.progress('close');
				}, 'JSON');
			}
		});
	}

	function editFun() {
		parent.$.modalDialog.handler = undefined;
		var row = _dataGrid.datagrid('getSelected');
		if(row == null) {
			return;
		}
		var id = row.id;
		parent.$.modalDialog({
			title : '修改快递费用',
			width : 340,
			height : 275,
			href : '/expressFeeController/editPage?id=' + id,
			buttons : [ {
				text : '确认修改',
				handler : function() {
					parent.$.modalDialog.openner_dataGrid = _dataGrid;//因为修改成功之后，需要刷新这个treeGrid，所以先预定义好
					var f = $("#form");
					f.submit();
				}
			} ]
		});
	}

	function addFun() {
		parent.$.modalDialog.handler = undefined;
		parent.$.modalDialog({
			title : '新增快递费用',
			width : 340,
			height : 335,
			href : '/expressFeeController/addPage?expressId=${expressId}',
			buttons : [ {
				text : '确认新增',
				handler : function() {
					parent.$.modalDialog.openner_dataGrid = _dataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
					var f = $("#form");
					f.submit();
				}
			} ]
		});
	}

	
</script>

<div class="easyui-layout" data-options="fit : true,border : false">
	<div data-options="region:'center',border:false">
		<table id="_dataGrid"></table>
	</div>
</div>
<div id="toolbar" style="display: none;">
	<a onclick="addFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'">新增</a>
	<a onclick="editFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'">修改</a>
	<a onclick="deleteFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-remove'">删除</a>
</div>

	